<template>
	<view class="invitation">
		<view class="header">
			<text class="title">邀请好友</text>
		</view>
		
		<view class="banner">
			<image class="banner-image" src="/static/muyuhome/yaofriend_bg.svg" mode="aspectFill"></image>
			<view class="banner-content">
				<text class="banner-title">邀请好友得奖励</text>
				<text class="banner-desc">每成功邀请1位好友，即可获得丰厚奖励</text>
				<view class="rewards">
					<view class="reward-item">
						<text class="reward-icon">💰</text>
						<text class="reward-text">10元优惠券</text>
					</view>
					<view class="reward-item">
						<text class="reward-icon">⭐</text>
						<text class="reward-text">100积分</text>
					</view>
				</view>
			</view>
		</view>
		
		<view class="stats-section">
			<view class="stat-item">
				<text class="stat-number">{{ stats.invitedCount }}</text>
				<text class="stat-label">已邀请好友</text>
			</view>
			<view class="stat-item">
				<text class="stat-number">{{ stats.rewardAmount }}</text>
				<text class="stat-label">累计奖励</text>
			</view>
			<view class="stat-item">
				<text class="stat-number">{{ stats.pendingReward }}</text>
				<text class="stat-label">待领取</text>
			</view>
		</view>
		
		<view class="invitation-code">
			<text class="code-title">我的邀请码</text>
			<view class="code-container">
				<text class="code-text">{{ invitationCode }}</text>
				<button class="copy-btn" @click="copyCode">复制</button>
			</view>
			<text class="code-tip">好友注册时输入此邀请码即可</text>
		</view>
		
		<view class="share-methods">
			<text class="section-title">分享方式</text>
			<view class="share-grid">
				<view class="share-item" @click="shareToWechat">
					<text class="share-icon">💬</text>
					<text class="share-name">微信好友</text>
				</view>
				<view class="share-item" @click="shareToMoments">
					<text class="share-icon">👥</text>
					<text class="share-name">朋友圈</text>
				</view>
				<view class="share-item" @click="shareToQQ">
					<text class="share-icon">💻</text>
					<text class="share-name">QQ好友</text>
				</view>
				<view class="share-item" @click="generatePoster">
					<text class="share-icon">🖼️</text>
					<text class="share-name">生成海报</text>
				</view>
			</view>
		</view>
		
		<view class="rules-section">
			<text class="section-title">活动规则</text>
			<view class="rules-list">
				<view v-for="rule in activityRules" :key="rule.id" class="rule-item">
					<text class="rule-number">{{ rule.id }}.</text>
					<text class="rule-text">{{ rule.content }}</text>
				</view>
			</view>
		</view>
		
		<view class="records-section">
			<view class="section-header">
				<text class="section-title">邀请记录</text>
				<text class="view-all" @click="viewAllRecords">查看全部</text>
			</view>
			<view class="records-list">
				<view v-for="record in recentRecords" :key="record.id" class="record-item">
					<image class="avatar" :src="record.avatar" mode="aspectFill"></image>
					<view class="record-info">
						<text class="friend-name">{{ record.name }}</text>
						<text class="invite-time">{{ record.time }}</text>
					</view>
					<view class="record-status" :class="getStatusClass(record.status)">
						{{ getStatusText(record.status) }}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue'

const stats = ref({
	invitedCount: 8,
	rewardAmount: 80,
	pendingReward: 20
})

const invitationCode = ref('A1B2C3D4')

const activityRules = ref([
	{ id: 1, content: '每成功邀请1位好友注册并完成首单，即可获得10元优惠券和100积分' },
	{ id: 2, content: '被邀请好友需使用您的邀请码完成注册' },
	{ id: 3, content: '奖励将在好友完成首单后24小时内发放' },
	{ id: 4, content: '每位用户最多可邀请50位好友' },
	{ id: 5, content: '活动最终解释权归平台所有' }
])

const recentRecords = ref([
	{ id: 1, name: '张三', avatar: '/static/muyuhome/headicon.jpg', time: '2024-01-15 14:30', status: 1 },
	{ id: 2, name: '李四', avatar: '/static/muyuhome/headicon.jpg', time: '2024-01-14 18:20', status: 2 },
	{ id: 3, name: '王五', avatar: '/static/muyuhome/headicon.jpg', time: '2024-01-13 10:15', status: 1 },
	{ id: 4, name: '赵六', avatar: '/static/muyuhome/headicon.jpg', time: '2024-01-12 16:45', status: 3 }
])

const copyCode = () => {
	uni.setClipboardData({
		data: invitationCode.value,
		success: () => {
			uni.showToast({
				title: '邀请码已复制',
				icon: 'success'
			})
		}
	})
}

const shareToWechat = () => {
	uni.share({
		provider: 'weixin',
		type: 0,
		title: '快来加入我们吧！',
		summary: '注册即可获得新人优惠，还有更多惊喜等你发现！',
		href: 'https://example.com',
		success: () => {
			uni.showToast({
				title: '分享成功',
				icon: 'success'
			})
		}
	})
}

const shareToMoments = () => {
	uni.showToast({
		title: '分享到朋友圈',
		icon: 'none'
	})
}

const shareToQQ = () => {
	uni.showToast({
		title: '分享到QQ',
		icon: 'none'
	})
}

const generatePoster = () => {
	uni.showToast({
		title: '生成分享海报',
		icon: 'none'
	})
}

const viewAllRecords = () => {
	uni.showToast({
		title: '查看全部记录',
		icon: 'none'
	})
}

const getStatusText = (status) => {
	const statusMap = {
		1: '已注册',
		2: '已下单',
		3: '奖励已发放'
	}
	return statusMap[status] || '未知'
}

const getStatusClass = (status) => {
	const classMap = {
		1: 'registered',
		2: 'ordered',
		3: 'rewarded'
	}
	return classMap[status] || ''
}
</script>

<style scoped>
.invitation {
	background: #f5f5f5;
	min-height: 100vh;
	padding: 20rpx;
}

.header {
	text-align: center;
	padding: 30rpx 0;
}

.title {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
}

.banner {
	position: relative;
	border-radius: 20rpx;
	overflow: hidden;
	margin-bottom: 30rpx;
}

.banner-image {
	width: 100%;
	height: 300rpx;
}

.banner-content {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(102, 126, 234, 0.9);
	color: white;
	padding: 40rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.banner-title {
	font-size: 36rpx;
	font-weight: bold;
	margin-bottom: 15rpx;
}

.banner-desc {
	font-size: 24rpx;
	opacity: 0.9;
	margin-bottom: 30rpx;
}

.rewards {
	display: flex;
	gap: 40rpx;
}

.reward-item {
	display: flex;
	align-items: center;
	gap: 10rpx;
}

.reward-icon {
	font-size: 32rpx;
}

.reward-text {
	font-size: 24rpx;
}

.stats-section {
	display: flex;
	justify-content: space-around;
	background: white;
	border-radius: 16rpx;
	padding: 40rpx 30rpx;
	margin-bottom: 30rpx;
}

.stat-item {
	text-align: center;
}

.stat-number {
	font-size: 40rpx;
	font-weight: bold;
	color: #ff6b6b;
	display: block;
	margin-bottom: 10rpx;
}

.stat-label {
	font-size: 22rpx;
	color: #666;
}

.invitation-code {
	background: white;
	border-radius: 16rpx;
	padding: 30rpx;
	margin-bottom: 30rpx;
}

.code-title {
	font-size: 28rpx;
	font-weight: bold;
	color: #333;
	display: block;
	margin-bottom: 20rpx;
}

.code-container {
	display: flex;
	align-items: center;
	gap: 20rpx;
	margin-bottom: 15rpx;
}

.code-text {
	flex: 1;
	background: #f8f9fa;
	border: 2rpx solid #eee;
	border-radius: 12rpx;
	padding: 20rpx;
	font-size: 28rpx;
	font-weight: bold;
	text-align: center;
	letter-spacing: 2rpx;
}

.copy-btn {
	background: #667eea;
	color: white;
	border: none;
	border-radius: 12rpx;
	padding: 20rpx 30rpx;
	font-size: 24rpx;
}

.code-tip {
	font-size: 20rpx;
	color: #999;
}

.share-methods,
.rules-section,
.records-section {
	background: white;
	border-radius: 16rpx;
	padding: 30rpx;
	margin-bottom: 30rpx;
}

.section-title {
	font-size: 28rpx;
	font-weight: bold;
	color: #333;
	display: block;
	margin-bottom: 25rpx;
}

.share-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 20rpx;
}

.share-item {
	background: #f8f9fa;
	border-radius: 12rpx;
	padding: 30rpx 20rpx;
	text-align: center;
	transition: all 0.3s;
}

.share-item:active {
	background: #e9ecef;
}

.share-icon {
	font-size: 48rpx;
	display: block;
	margin-bottom: 15rpx;
}

.share-name {
	font-size: 24rpx;
	color: #333;
}

.rules-list {
	display: flex;
	flex-direction: column;
	gap: 20rpx;
}

.rule-item {
	display: flex;
	gap: 15rpx;
}

.rule-number {
	font-size: 22rpx;
	color: #667eea;
	font-weight: bold;
	min-width: 40rpx;
}

.rule-text {
	font-size: 22rpx;
	color: #666;
	line-height: 1.5;
	flex: 1;
}

.section-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 25rpx;
}

.view-all {
	font-size: 24rpx;
	color: #667eea;
}

.records-list {
	display: flex;
	flex-direction: column;
	gap: 25rpx;
}

.record-item {
	display: flex;
	align-items: center;
	gap: 20rpx;
	padding-bottom: 25rpx;
	border-bottom: 1rpx solid #f0f0f0;
}

.record-item:last-child {
	border-bottom: none;
	padding-bottom: 0;
}

.avatar {
	width: 80rpx;
	height: 80rpx;
	border-radius: 50%;
}

.record-info {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 5rpx;
}

.friend-name {
	font-size: 26rpx;
	color: #333;
	font-weight: bold;
}

.invite-time {
	font-size: 20rpx;
	color: #999;
}

.record-status {
	font-size: 22rpx;
	padding: 8rpx 16rpx;
	border-radius: 20rpx;
}

.record-status.registered {
	background: #fff7e6;
	color: #fa8c16;
}

.record-status.ordered {
	background: #f6ffed;
	color: #52c41a;
}

.record-status.rewarded {
	background: #f0f3ff;
	color: #667eea;
}
</style>